import {
  getDeviceTypeTree,
  getDeviceTree,
  getDevicePointTree,
  getDeviceType
} from "@/api/myApi/info";

const user = {
  state: {
    deviceTypeTree: null,
    deviceTree: null,
    devicePointTree: null,
    deviceType: null,
  },

  mutations: {
    SET_deviceTypeTree: (state, deviceTypeTree) => {
      state.deviceTypeTree = deviceTypeTree;
    },
    SET_deviceTree: (state, deviceTree) => {
      state.deviceTree = deviceTree;
    },
    SET_devicePointTree: (state, devicePointTree) => {
      state.devicePointTree = devicePointTree;
    },
    SET_deviceType: (state, deviceType) => {
      state.deviceType = deviceType;
    },
  },

  actions: {
    // 设备类型树
    getDeviceTypeTree({ commit }) {
      return new Promise((resolve, reject) => {
        getDeviceTypeTree()
          .then((res) => {
            commit("SET_deviceTypeTree", res.data);
            resolve(res.data.deviceTypeCode);
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
    // 设备树
    getDeviceTree({ commit }) {
      return new Promise((resolve, reject) => {
        getDeviceTree()
          .then((res) => {
            commit("SET_deviceTree", res.data);
            resolve(res.data.code);
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
    // 设备测点树
    // getDevicePointTree({ commit }) {
    //   return new Promise((resolve, reject) => {
    //     getDevicePointTree()
    //       .then((res) => {
    //         commit("SET_devicePointTree", res.data);
    //         resolve(res.data.code);
    //       })
    //       .catch((error) => {
    //         reject(error);
    //       });
    //   });
    // },

    // 设备类型 健康状态汇总，主机资源监控
    getDeviceType({ commit }) {
      return new Promise((resolve, reject) => {
        getDeviceType()
          .then((res) => {
            commit("SET_deviceType", res.data);
            resolve(res.data.code);
          })
          .catch((error) => {
            reject(error);
          });
      });
    },
  },
};

export default user;
